package com.kd.juhaowan.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.Nullable;


import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallbackProxy;
import com.kd.juhaowan.R;
import com.kd.juhaowan.http.api.CommonApi;
import com.kd.juhaowan.http.model.HttpData;
import com.kd.juhaowan.http.model.MineResult;
import com.kd.juhaowan.utils.LogUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class AccountManagerActivity extends BaseActivity {





    @BindView(R.id.activity_title)
    TextView titleView;
    @BindView(R.id.accountmanager_idcard_tip)
    TextView idcardTipView;
    @BindView(R.id.accountmanager_phone_tip)
    TextView phoneTipView;
    private MineResult mineInfo;

    @Override
    protected void reInitDate() {
     initData();
    }
    public static boolean needRefresh=true;
    private void initData(){
        needRefresh =false;
        EasyHttp.post(this).api(new CommonApi("api/userinfo")).request(new HttpCallbackProxy<HttpData<MineResult>>(this){
            @Override
            public void onHttpSuccess(HttpData<MineResult> result, boolean cache) {
                super.onHttpSuccess(result, cache);
                LogUtil.debugLog("AccountManagerActivity"+needRefresh);
                mineInfo = result.getData();
//                        LogUtil.debugLog(result.getData().getAccess_token());
//                        Toast.makeText(AccountLoginActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
//                bannerModels = result.getData();
                setView();
//                onRefresh(getSmartRefreshLayout());
            }
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }



    @Override
    protected void onResume() {
        super.onResume();
        if(needRefresh)initData();
    }

    private void setView(){
        idcardTipView.setText(TextUtils.isEmpty(mineInfo.getId_card())?"去认证":mineInfo.getId_card());
        phoneTipView.setText(TextUtils.isEmpty(mineInfo.getMobile())?"绑定":mineInfo.getMobile());

    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        needRefresh = true;
        titleView.setText("账号与绑定");
//        setContentView(R.layout.activity_account_login);

    }
    @OnClick(R.id.actvity_back)
    public void onBackClick(){
        finish();
    }
    @OnClick(R.id.manager_realname)
    public void onRealNameClick(){
        if(mineInfo==null){
            return;
        }
        Intent intent = new Intent(this,SettingRealnameActivity.class);
        intent.putExtra("user",mineInfo);
        startActivity(intent);
    }

    @OnClick(R.id.accountmanager_logoff_layout)
    public void onLogoffClick(){
        if(mineInfo==null){
            return;
        }
        Intent intent = new Intent(this,LogoffAccountActivity.class);
        intent.putExtra("user",mineInfo);
        startActivity(intent);
    }

    @OnClick(R.id.accountmanager_phone_layout)
    public void onPhoneClick(){
        if(mineInfo==null){
            return;
        }
        if(TextUtils.isEmpty(mineInfo.getMobile())){
            startActivity(new Intent(this,PhoneBindActivity.class));
        }else{
            Intent intent = new Intent(this,BindChange1Activity.class);
            intent.putExtra("phone",mineInfo.getMobile());
            startActivity(intent);
        }
    }


    @OnClick(R.id.manager_pwd)
    public void onPasswordClick(){
        if(mineInfo==null){
            return;
        }
        startActivity(new Intent(this,PwdManagerActivity.class));
    }
    @Override
    protected int getViewLayoutResourceId() {
        return R.layout.activity_accountmanager;
    }




}
